﻿using D20;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace D20.UnitTests.Characters
{


    /// <summary>
    ///This is a test class for DiceTest and is intended
    ///to contain all DiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class DiceTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        Random r = new Random();

        /// <summary>
        ///A test for Roll
        ///</summary>
        [TestMethod()]
        public void RollTest()
        {
            for (int i = 0; i < 5000; i++)
            {
                checked
                {
                    int numberOfDie = r.Next(-100,100);
                    int sidesPerDie = r.Next(-500,500);
                    int modifier = r.Next(-50000, 50000);
                    int expectedMin = numberOfDie + modifier;
                    int expectedMax = numberOfDie * sidesPerDie + modifier;
                    if (numberOfDie <= 0 || sidesPerDie <= 0)
                    {
                        try
                        {
                            Dice.Roll(numberOfDie, sidesPerDie, modifier);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                    int actual = Dice.Roll(numberOfDie, sidesPerDie, modifier);
                    Assert.IsTrue(actual >= expectedMin, "actual >= expectedMin; actual = {0}, expectedMin = {1}", actual, expectedMin);
                    Assert.IsTrue(actual <= expectedMax, "actual <= expectedMax; actual = {0}, expectedMax = {1}", actual, expectedMax);
                }
            }
        }
    }
}
